<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的saas管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.niucloud-admin.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------

namespace app\api\controller\login;

use app\api\service\login\LoginService;
use app\core\base\BaseController;


use Exception;
use think\Response;

class Login extends BaseController
{

     /**
      * 登出
      * @return Response
      */
     public function logout()
     {
          (new LoginService())->logout();
          return success('MEMBER_LOGOUT');
     }


     /**
      * 发送手机验证码
      * @param $type
      * @return Response
      * @throws Exception
      */
     public function sendMobileCode($type)
     {
          $data = $this->request->params([
               ['mobile', ''],
          ]);
          return success((new LoginService())->sendMobileCode($data['mobile'], $type));
     }

     /**
      * 手机号登录
      * @return Response
      */
     public function mobile()
     {
          $data = $this->request->params([
               ['mobile', ''],
          ]);
          return success((new LoginService())->mobile($data['mobile']));
     }

     /**
      * 重置密码
      * @return Response
      */
     public function resetPassword()
     {
          $data = $this->request->params([
               ['mobile', ''],
               ['password', '']
          ]);
          //参数验证
          $this->validate($data, 'app\validate\member\Member.reset_password');
          (new LoginService())->resetPassword($data['mobile'], $data['password']);
          return success('PASSWORD_RESET_SUCCESS');
     }

     //微信小程序登录
     public function wechat()
     {
          $data = $this->request->params([
               ['code', ''],
               ['encryptedData', ''],
               ['iv', ''],
          ]);
          return success((new LoginService())->wechat($data['code'], $data['encryptedData'], $data['iv']));
     }
}
